//
//  UIViewExtensions.swift
//  SwiftWeather
//
//  Created by shen on 2023/8/28.
//

import UIKit

extension UIView {
    func addSubview(_ view: UIView, useAutoLayout: Bool) {
        view.translatesAutoresizingMaskIntoConstraints = !useAutoLayout
        addSubview(view)
    }

    func padded(_ inset: CGFloat) -> UIStackView {
        padded(insets: .init(top: inset, left: inset, bottom: inset, right: inset))
    }

    func padded(insets: UIEdgeInsets) -> UIStackView {
        let stack = UIStackView(arrangedSubviews: [self], axis: .vertical)
        stack.layoutMargins = insets
        stack.isLayoutMarginsRelativeArrangement = true
        return stack
    }
}
